package cn.tedu.jdbc;

import java.sql.Connection;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.sql.Statement;
import java.util.Scanner;

public class JDBCLogin {
    public static void main(String[] args) {
        try (Connection connection = DBUtil.getConnection();) {

            Scanner scan = new Scanner(System.in);
            System.out.println("用户名：");
            String userName = scan.nextLine();
            System.out.println("密码：");
            String passWord = scan.nextLine();
            //执行SQL
            Statement statement = connection.createStatement();
            String sql = "SELECT nickName FROM userinfo WHERE userName= '" + userName + " 'AND passWord= '" + passWord + "'";
            ResultSet resultSet = statement.executeQuery(sql);
            if (resultSet.next()) {
                String nickName = resultSet.getString("nickName");
                System.out.println("登录成功，欢迎你：" + nickName);
            } else {
                System.out.println("用户名或密码错误");
            }
        } catch (SQLException e) {
            throw new RuntimeException(e);
        }


    }
}
